# coding=utf-8
"""
Created on 2010-8-8

@author: morningbzy
"""

from card_base import CardBase
from sgs.common.constants import userState, cardType
from shan import Shan

class Sha(CardBase):
    name = '杀'
    def __init__(self, id, color, point):
        CardBase.__init__(self, id, color, point, cardType.BASIC)

    def action(self, cond, src, args):
        if src.state not in (userState.ROUND_BEGIN, userState.IN_DUEL):
            src.addCmd('BROKE_RULE', ['你现在不能出杀'])
            return
        if len(args) != 1 or not args[0]:
            src.addCmd('BROKE_RULE', ['你一刀杀且只杀一人'])
            return
        target = src.useSha(cond, int(args[0]))
        if not target:
            return
        print '%s SHA %s' % (src.name, target.name)
        src.removeCard(self.id)
        #TODO: verify validation of target
        cards, _ = target.requireCard(cond, condition={'class': Shan},
                msg='%s对你使用了【杀】，需要打出【闪】' % src.name,
                target=False)
        if cards and cards[0]:
            target.removeCard(cards[0].id)
            target.useShan(cond, src)
            src.beShan(cond, target)
        else:
            target.beDamage(cond, src, self, -1)
            self.originalCard = self

    def getDamage(self, src, dest):
        return -1
